package com.comp490.pattern;

import java.util.List;

import android.graphics.Canvas;

import com.comp490.bullet.Bullet;
import com.comp490.shooter.GameView;
import com.comp490.sprite.Ship;

public abstract class BulletPattern
{
    public static float PI = 3.1415927410125732421875f;
    protected float x;
    protected float y;
    protected boolean active;
    protected List<Bullet> bullets;
    protected GameView gameView;

    public static float toRadians(float degrees)
    {
        return degrees * PI / 180;
    }

    public BulletPattern(List<Bullet> blts, GameView gv, boolean act)
    {
        bullets = blts;
        active = act;
        gameView = gv;
    }

    public void draw(Canvas c)
    {
        if(active)
        	for(int i = 0; i < bullets.size(); i++)
        	{
        		if(bullets.get(i).isActive())
        			bullets.get(i).draw(c);
        	}
    }

    public boolean isActive()
    {
        return active;
    }

    /**
     * Moves object in a straight line based on input parameters.
     * 
     * @param delta
     *            total displacement in number of pixels
     * @param theta
     *            angle of displacement in degrees (the y-axis is inverted so
     *            the angle will grow clockwise)
     */
    public void moveLine(float delta, float theta)
    {
        x += delta * android.util.FloatMath.cos(toRadians(theta));
        y += delta * android.util.FloatMath.sin(toRadians(theta));
    }

    public void setCoordinates(float x, float y)
    {
        this.x = x;
        this.y = y;
    }

    public abstract void reset();

    public abstract void moveAndCheckCollision(List<? extends Ship> ships);
}